package com.yiyang.exception;

import com.yiyang.constant.ResultCode;
import com.yiyang.domain.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionAdvice {

    // 未知异常
    @ExceptionHandler(Exception.class)
    public Result exceptionHandler(Exception e){
        e.printStackTrace();
        return Result.fail(ResultCode.UNKOWNE_CODE,"当前网络不稳定，请稍后再试");
    }

    // 业务异常
    @ExceptionHandler(BusinessException.class)
    public Result businessExceptionHandler(BusinessException e){
        e.printStackTrace();
        return Result.fail(e.getCode(),e.getMessage());
    }
}
